#include<stdio.h>
#include<stdlib.h>
#include"double_link.h"
#include<string.h>

#define NAMESIZE 32

typedef struct
{
	int id;
	char name[NAMESIZE];
	int math;
	int chinese;
}message_st;

static void print_st(const void *recod)
{
	const message_st *r = recod;
	printf("%d %s %d %d\n",r->id,r->name,r->math,r->chinese);
}

static int find(const void *record,const void *key)
{
	const message_st *dest = record;
	const int *src = key;
	return (*src - dest->id);
}


	int main()
{
	int i,ret = 0;
	int id = 3;
	void *data;
	message_st stu;
	LList_st *ar;
	ar = llist_create(sizeof(message_st));
	if(ar == NULL)
		exit(1);
	
	for(i = 0;i < 5;i++)
	{
		stu.id = i;
		snprintf(stu.name,NAMESIZE,"stu%d",i);
		stu.math = rand()%100;
		stu.chinese = rand()%100;

		ret = llist_insert(ar,&stu,FRONT);
		if(ret)
			exit(1);
	}
	
	llist_display(ar,print_st);
	printf("\n\n");
//	data = llist_find(ar,&id,find);
//	if(data == NULL)
//		printf("NO find!");
//	else
//		print_st(data);
	data = malloc(sizeof(message_st));
	if(data == NULL)
		return -1;
	llist_fcget(ar,&id,find,data);
	printf("\n\n");
	llist_display(ar,print_st);
	printf("\n");
	print_st(data);
	llist_distory(ar);
	exit(0);
}
